﻿using System.Linq;

using Microsoft.WowAddonStudio.Lua.Model;

using NUnit.Framework;

namespace Microsoft.WowAddonStudio.Lua.Tests.Model
{
    [TestFixture]
    public class DocumentationTest : DocumentationTestBase
    {
        private Documentation documentation;

        public override void SetUp()
        {
            base.SetUp();

            // Deserialize Widget API documentation
            documentation = this.DeserializeDocumentation(widgetApiRelativePath);
        }

        [Test]
        public void FindVariableExactNameTest()
        {
            documentation.Add(new Variable { Type = LuaType.Number, Name = "foo"});

            // Find the variable declaration by its exact name
            var frame1 = documentation.Resolve<Variable>("foo");

            Assert.IsNotNull(frame1);
        }

        [Test]
        public void AddTableWithPrototypeTest()
        {
            // Add table declaration
            documentation.Add(new Table { Name = "Frame1", Prototype = "Frame", Summary = "<Frame name='Frame1' />" });

            // Find the table declaration by its exact name
            var frame1 = documentation.Resolve<Table>("Frame1");

            // Assert that frame1 has function declarations on it
            Assert.AreNotEqual(0, frame1.Declarations.OfType<Function>().Count());
        }
    }
}